package org.o14x.alpha.ui.commands;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.o14x.alpha.ui.controller.UIController;
import org.o14x.alpha.ui.views.folder.FolderView;

/**
 * The command for opening a new tab;
 * 
 * @author Olivier DANGREAUX
 */
public class NewTabCommand extends AbstractHandler {
	private UIController uiController;

	@Override
	/**
	 * {@inheritDoc}	 
	 */
	public Object execute(ExecutionEvent event) throws ExecutionException {
		System.out.println("\u03B1"); //$NON-NLS-1$

		uiController.getDomain().setCurrentExplorerTab(uiController.getDomain().getExplorerTabManager().getNewExplorerTab());
		uiController.getUi().getFolderTreeView().update();
		try {
			PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(FolderView.ID, uiController.getDomain().getCurrentExplorerTab().getId(), IWorkbenchPage.VIEW_ACTIVATE);
		} catch (PartInitException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		uiController.getDomain().getCurrentExplorerTab().getFolderView().update();

		return null;
	}

	/**
	 * Returns the value of uiController.
	 *
	 * @return The value of uiController.
	 */
	public UIController getUiController() {
		return uiController;
	}

	/**
	 * Sets the value of uiController.
	 *
	 * @param uiController The value of uiController to set.
	 */
	public void setUiController(UIController uiController) {
		this.uiController = uiController;
	}
}
